#pragma once
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <cerrno>
#include <cstdlib>

class InetAddr{
private:
    void GetAddress(std::string* ip, uint16_t* port){
            *port = ntohs(_addr.sin_port);
            *ip = inet_ntoa(_addr.sin_addr);
        }
public:
    InetAddr(sockaddr_in& addr):_addr(addr){
        GetAddress(&_ip, &_port);
    }

    bool operator==(const InetAddr& addr){
        if(addr._ip == _ip && addr._port == _port) return true;
        return false;
    }
    std::string Getip(){
        return _ip;
    }

    uint16_t Getport(){
        return _port;
    }

    struct sockaddr_in GetAddr(){
        return _addr;
    }

private:
    uint16_t _port;
    std::string _ip;
    sockaddr_in _addr; 
};